# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/30 下午3:15
 @Author  : tgy
 
"""
import io
from urllib.request import urlopen

class MyBuffer:

    def __init__(self,content:str):
        self.content = content


    def read(self):
        return self.content.encode('utf-8')

    def writable(self):
        ...
        return True

    def readable(self):
        return True

    def seekable(self):
        return True

def test01():
    ...
    f = open('./item_demo.py',mode='r')
    # print(f.buffer)
    # buffer = MyBuffer("君不见黄河之水天上来")
    # ft = io.TextIOWrapper(buffer, encoding='utf-8')
    # print(ft.read())
    print(f.buffer.raw)

def test02():
    ...
    response = urlopen('http://www.baidu.com')
    print(type(response))
    response_decode = io.TextIOWrapper(response, encoding='utf-8')
    print(response_decode.readline())


if __name__ == '__main__':
    ...
    # test01()
    # test02()
    import sys
    # sys.stdout.buffer.write(b'aaa')
    # sys.stdout.write('aaa')
    print(sys.stdout.buffer)
    test01()
